/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on 28.2.2011, 22:41:39
 */
package cz.pd.projectbuilder.main.gui;

import cz.pd.projectbuilder.beans.load.ProjectBuilderBean;
import cz.pd.projectbuilder.main.gui.panel.ProjectMoveFrame;
import cz.pd.projectbuilder.main.listener.ProjektyListener;
import cz.pd.projectbuilder.main.util.BeanUtils;
import cz.pd.projectbuilder.main.util.ListenersUtils;
import cz.pd.projectbuilder.main.util.XmlUtils;
import java.beans.Beans;
import javax.swing.ImageIcon;
import javax.swing.border.Border;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import org.slf4j.Logger;

/**
 *
 * @author forrest
 */
public class MainFrame extends javax.swing.JFrame {

  private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(MainFrame.class);

  /** Creates new form MainFrame */
  public MainFrame() {
    initComponents();
    if (!Beans.isDesignTime()) {
      setSize(1650, 816);
//    setResizable(false);
      setLocationRelativeTo(null);
      ImageIcon imageIcon = new javax.swing.ImageIcon(getClass().getResource("/icons/excel.png"));
      setIconImage(imageIcon.getImage());
      jSplitPane1.setUI(new BasicSplitPaneUI() {

        @Override
        public BasicSplitPaneDivider createDefaultDivider() {
          return new BasicSplitPaneDivider(this) {

            @Override
            public void setBorder(Border b) {
            }
          };
        }
      });
      jSplitPane1.setBorder(null);
      loadProjectBuilder();
    }
  }

  private void loadProjectBuilder() {
    ProjectBuilderBean projectBuilder = XmlUtils.loadMainProjectBuilder();
    ProjectBuilderBean projectBuilderComplete = BeanUtils.completeAllPathInProjctBean(projectBuilder);
    ListenersUtils.fire(ProjektyListener.class).afterLoadProjectsData(projectBuilderComplete.getProjectGroupBeans());
    ListenersUtils.fire(ProjektyListener.class).afterLoadSuitsData(projectBuilderComplete.getSuiteGroupBeans());
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    buttonsFrame = new cz.pd.projectbuilder.main.gui.panel.ButtonsPanel();
    jSplitPane1 = new javax.swing.JSplitPane();
    infoFrame = new cz.pd.projectbuilder.main.gui.panel.InfoPanel();
    obsahPanel1 = new cz.pd.projectbuilder.main.gui.panel.ObsahPanel();
    menuBar = new javax.swing.JMenuBar();
    javax.swing.JMenu fileMenu = new javax.swing.JMenu();
    javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
    javax.swing.JMenu helpMenu = new javax.swing.JMenu();
    helpMenuItem = new javax.swing.JMenuItem();
    javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("cz/pd/projectbuilder/main/gui/Bundle"); // NOI18N
    setTitle(bundle.getString("MainFrame.title")); // NOI18N
    setMinimumSize(new java.awt.Dimension(300, 30));
    getContentPane().setLayout(new java.awt.GridBagLayout());
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
    getContentPane().add(buttonsFrame, gridBagConstraints);

    jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
    jSplitPane1.setResizeWeight(0.5);
    jSplitPane1.setRightComponent(infoFrame);
    jSplitPane1.setLeftComponent(obsahPanel1);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0);
    getContentPane().add(jSplitPane1, gridBagConstraints);

    fileMenu.setText(bundle.getString("MainFrame.fileMenu.text")); // NOI18N

    javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(MainFrame.class, this);
    exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
    fileMenu.add(exitMenuItem);

    menuBar.add(fileMenu);

    helpMenu.setText(bundle.getString("MainFrame.helpMenu.text")); // NOI18N

    helpMenuItem.setAction(actionMap.get("showHelpBox")); // NOI18N
    helpMenuItem.setText(bundle.getString("MainFrame.helpMenuItem.text")); // NOI18N
    helpMenuItem.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        napoveda(evt);
      }
    });
    helpMenu.add(helpMenuItem);

    aboutMenuItem.setText(bundle.getString("MainFrame.aboutMenuItem.text")); // NOI18N
    aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        about(evt);
      }
    });
    helpMenu.add(aboutMenuItem);

    menuBar.add(helpMenu);

    setJMenuBar(menuBar);

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void about(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_about
      ProjectMoveFrame moveFrame = new ProjectMoveFrame();
      moveFrame.setLocationRelativeTo(this);
      moveFrame.setVisible(true);
    }//GEN-LAST:event_about

    private void napoveda(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_napoveda
    }//GEN-LAST:event_napoveda
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private cz.pd.projectbuilder.main.gui.panel.ButtonsPanel buttonsFrame;
  private javax.swing.JMenuItem helpMenuItem;
  private cz.pd.projectbuilder.main.gui.panel.InfoPanel infoFrame;
  private javax.swing.JSplitPane jSplitPane1;
  private javax.swing.JMenuBar menuBar;
  private cz.pd.projectbuilder.main.gui.panel.ObsahPanel obsahPanel1;
  // End of variables declaration//GEN-END:variables
}
